package com.icss.th.question.service;

import com.icss.th.common.FacadeFactory;
import com.icss.th.common.exception.ThException;
import com.icss.th.common.util.StringUtil;
import com.icss.th.question.facade.IQuestionFacade;
import com.icss.th.question.pojo.Question;

public class QuestionService 
{
	private static IQuestionFacade questionFacade = (IQuestionFacade)FacadeFactory.getInstance(IQuestionFacade.class);
	
	/**
	 * 得到兄弟试题
	 * @param paperid
	 * @param sort
	 * @param next true为下一题，false为上一题
	 * @return
	 * @throws Exception 
	 */
	public static Question getBrotherQuestion(String id, String paperid, String sort, boolean next) throws ThException
	{
		Question question = null;
		
		try
		{
			String questionId = id;
			if (!StringUtil.isEmpty(paperid) && !StringUtil.isEmpty(sort))
			{
				String brotherId = questionFacade.getBrotherId(paperid, sort, next);
				if (!StringUtil.isEmpty(brotherId)) questionId = brotherId;
			}
			
			question = questionFacade.getQuestion(questionId);
		}
		catch (ThException e)
		{
			throw e;
		}
		
		return question;
	}
}
